// 引入mutations的常量
import { SET_CATEGORYLIST_STATE } from "../constant-types";
// 引入api中的请求方法
import { reqCategoryList } from "@/api";

const state = {
  categoryList: [],
};

const mutations = {
  [SET_CATEGORYLIST_STATE](state, payload) {
    state.categoryList = payload.categoryList;
  },
};

const actions = {
  async getCategoryList({ commit }) {
    try {
      let re = await reqCategoryList();
      commit(SET_CATEGORYLIST_STATE, { categoryList: re });
    } catch (err) {
      alert(err.message);
    }
  },
};

const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
